﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPHP
{
    public partial class leftColumn : System.Web.UI.UserControl
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            conn.Open();

            if (Session["id"] != null)
            {
                Panel1.Visible = true;
                Panel2.Visible = true;
                lblUsername.Text = Session["username"].ToString();

                if (Session["Role"].ToString() == "Admin" || Session["Role"].ToString() == "Staff")
                {
                    Panel2.Visible = false;
                    Panel3.Visible = true;
                }
                else if (Session["Role"].ToString() == "ShopOwner")
                {
                    lblVirtuallink.Text = "<a href='http://localhost:34874/Reports/VirtualReport.aspx?id=" + Session["id"] + "'>Virtual Shop Report</a>";
                    PanelShopowner.Visible = true;
                }
            }
            else
            {
                Panel1.Visible = false;
                Panel2.Visible = false;
            }

            SqlCommand cmdS = new SqlCommand("SELECT * FROM Category WHERE cat_status='publish' ORDER BY cat_name", conn);
            SqlDataReader dtrS = cmdS.ExecuteReader();

            String ul = "<ul>";

            if(dtrS.HasRows)
            {
                while(dtrS.Read())
                {
                    ul += "<li><a href='http://localhost:34874/ProductsByCategory.aspx?id=" + dtrS["cat_id"].ToString() + "'>" + dtrS["cat_name"].ToString() + "</a></li>";
                }
            }
            ul += "</ul>";
            lblUL.Text = ul;

            dtrS.Close();
            conn.Close();
        }

        public String return_userpicture()
        {
            SqlCommand cmdUser;
            SqlDataReader dtrUser;
            conn.Open();

            cmdUser = new SqlCommand("Select * From Users WHERE u_id=@UID", conn);
            cmdUser.Parameters.AddWithValue("@UID", Session["ID"]);
            dtrUser = cmdUser.ExecuteReader();
            dtrUser.Read();
            String userPicture = dtrUser["u_picture"].ToString();

            conn.Close();

            return userPicture;

        }
    }
}